<!--
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-08-16 21:07:04
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-08-27 10:06:58
 * @FilePath: \后端管理系统\app\src\views\Home.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <el-container class="home_container">
    <el-header style="height: 60px" class="home_header">
      <div class="header_logo">
        <img src="../assets/logo.png" alt="" />
      </div>
      <el-button class="btn_back" @click="back">退出</el-button>
    </el-header>
    <el-container>
      <el-aside class="home_aside" :width="isCollapse ? '50px':'200px'">
        <div class="toggle_button" @click="toggleIsCollapse">|||</div>
        <el-menu 
        router 
        :collapse="isCollapse"
        class="el-menu-vertical-demo"
        background-color="#313743"
        text-color='#fff'
        active-text-color='#409EFF'
        :default-active='$route.path'
        >
         <el-menu-item index="welcome">
          <i class="el-icon-s-home"></i>
           <span slot="title">首页</span>
         </el-menu-item>
          
          <el-submenu
            v-for="(item,index) in menuList"
            :key="item.id"
            :index="item.id + ''"
          >
            <template slot="title">
              <i :class="icons[index]"></i>
              <span slot="title" >{{ item.authName }}</span>
            </template>
            
            <el-menu-item
            v-for="(items,index) in item.children"
            :key="items.id"
             :index="'/'+items.path"
             > 
                 <i :class="icons[index]"></i>
                 <span>{{ items.authName }}</span>
            </el-menu-item>
           
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import { httpMenu } from "../api/home";
export default {
  data() {
    return {

      menuList: [],
      // 图标
      icons:[
        'el-icon-user',
        'el-icon-setting',
        'el-icon-goods',
        'el-icon-s-order',
        'el-icon-s-claim'
      ],
      //是否展开
      isCollapse:false,
    };
  },
  created() {
    this.initMenu();
  },
  methods: {
    async initMenu() {
      const res = await httpMenu("/menus");
      this.menuList = res.data.data;
    },
    // 是否展开
    toggleIsCollapse(){
      this.isCollapse=!this.isCollapse;
    },
    // 退出登录
    back(){
      sessionStorage.clear('token');
      this.$router.push('/login')
    }
  },
};
</script>
<style>
.home_container {
  width: 100%;
  height: 100%;
}

.home_header {
  background: rgb(54, 61, 64);
  font-size: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
}

.header_logo {
  height: 50px;
}
.header_logo img {
  width: 100%;
  height: 100%;
}
.home_aside{
  height: 100%;
  background:rgb(49, 55, 67) ;
}
/* 是否展开 */
.toggle_button{
  color: #fff;
  text-align: center;
  cursor: pointer;
}
</style>